package net.skyedu.service.myattend;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.skyedu.bean.Attendance;
import net.skyedu.dao.UserInfoDao;

public class Choose extends HttpServlet {

	private static final long serialVersionUID = -7452492747665303419L;

	public Choose() {
		super();
	}

	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("text/html;charset=UTF-8");
		doPost(request,response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("text/html;charset=UTF-8");
		request.setCharacterEncoding("UTF-8");
		String qstr=request.getParameter("qstr");
//		System.out.println(qstr);
		String qx = "";
		if(qstr != null && !"".equals(qstr)){
//			System.out.println(qstr.lastIndexOf(","));
			if(qstr.lastIndexOf(",") != -1){
				qx = qstr.substring(0,qstr.lastIndexOf(","));
			}else{
				qx = qstr;
			}
		}
//		System.out.println(qx);
		String currentPage=request.getParameter("currentPage");
		
		UserInfoDao ufd = new UserInfoDao();
		Attendance att = new Attendance();
		att.setAttconfirm(1);
		att.setAttupdatestate(4);
		int num = ufd.updateConfirm(att,qx);
		StringBuffer jsonAttr = new StringBuffer("[{");
//		boolean flag = false;
		if(num > 0){
			jsonAttr.append("\"curPage\":\""+currentPage+"\",");
			jsonAttr.append("\"jason\":\""+1+"\"");
		}else{
			jsonAttr.append("\"curPage\":\""+currentPage+"\",");
			jsonAttr.append("\"jason\":\""+0+"\"");
		}
		jsonAttr.append("}]");
		 PrintWriter out = response.getWriter();
		 out.print(jsonAttr);
		 out.flush();
		 out.close();
		 
		
//		if(h!=null&&h!=""){
//			int b=h.lastIndexOf(",");
//			String a=h.substring(0,b);
//			String[] idlist=a.split(",");
//			UserInfoDao ufd=new UserInfoDao();
//			int num=0;
//			for(int i=0;i<idlist.length;i++){
//				Attendance att=new Attendance();
//				att.setAttid(Integer.parseInt(idlist[i]));
//				att.setAttconfirm(1);
//				att.setAttupdatestate(4);
//				num=ufd.updateConfirm(att);
//			}
//			if(num > 0){
//					request.getRequestDispatcher("MonthUser?sta="+status+"&currentPage="+currentPage).forward(request, response);
//			}else{
//				out.print("<script type='text/javascript'>alert('ERROR:Choose');history.go(-1);</script>");
//			}
//		}else{
//			out.print("<script type='text/javascript'>alert('请选中后再确认');history.go(-1);</script>");
//		}
	}

	public void init() throws ServletException {}
}
